package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.bo.LogiPickupOrderEditBo;
import com.piggy.logi.sys.bo.LogiPickupOrderQueryBo;
import com.piggy.logi.sys.service.ILogiPickupOrderService;
import com.piggy.logi.sys.vo.LogiPickupOrderExtVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 提货单Controller
 *
 * @author piggy
 * @date 2023-08-25
 */
@Api(value = "提货单控制器", tags = {"提货单管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/pickup")
public class LogiPickupOrderController extends BaseController {

    private final ILogiPickupOrderService iLogiPickupOrderService;

    /**
     * 查询提货单列表
     */
    @ApiOperation("查询提货单列表")
    //@SaCheckPermission("sys:pickup:list")
    @GetMapping("/list")
    public TableDataInfo<LogiPickupOrderExtVo> list(@Validated LogiPickupOrderQueryBo bo) {
        startPage(bo);
        return iLogiPickupOrderService.queryPageList(bo);
    }

    /**
     * 获取提货单详细信息
     */
    @ApiOperation("获取提货单详细信息")
    //@SaCheckPermission("sys:pickup:query")
    @GetMapping("/{id}")
    public R<LogiPickupOrderExtVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iLogiPickupOrderService.queryById(id));
    }

    /**
     * 获取提货单详细信息
     */
    @ApiOperation("根据运单ID获取提货单详细信息")
    //@SaCheckPermission("sys:pickup:query")
    @GetMapping("/waybill/{waybillId}")
    public R<LogiPickupOrderExtVo> getPickUp(@NotNull(message = "主键不能为空")
                                        @PathVariable("waybillId") Long waybillId) {
        return R.ok(iLogiPickupOrderService.queryByWaybillId(waybillId));
    }

    /**
     * 新增提货单
     */
    @ApiOperation("新增或修改提货单")
    //@SaCheckPermission("sys:pickup:add")
    @LogiLog(title = "提货单", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public R<LogiPickupOrderExtVo> save(@Validated @RequestBody LogiPickupOrderEditBo bo) {
        return R.ok(iLogiPickupOrderService.insertByAddBo(bo));
    }

    /**
     * 删除提货单
     */
    @ApiOperation("删除提货单")
    //@SaCheckPermission("sys:pickup:remove")
    @LogiLog(title = "提货单" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiPickupOrderService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
